Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




count( ) FUNCTION


count( ) Function is used to specify the number of times an element is present in the List.


Let us say, we have a List that contains three names, 'Mohan', 'Kriti' and 'Salim'. And we want to find how many times 'Mohan' is present in the List.


Example :


x = ["Mohan", "Kriti", "Mohan", "Salim"]
y = x.count("Mohan")
print("The count of Mohan is ",y)


Output :



  The count of Mohan is 2

So, in the above code we have created a 'List' and initialised to the variable 'x'.


x = ["Mohan", "Kriti", "Mohan", "Salim"]

Below is how the values are positioned in the List,


java_Collections

Now, if we see the above diagram, 'Mohan' is present '2' times in the above List.


And the 'count( )' Function is used to find how many times 'Mohan' is present.


y = x.count("Mohan")

And we get the below output,


The count of Mohan is 2